Redis在VMware虚拟机中本地连接调试错误解决

8,708次阅读
33 条评论

共计 1700 个字符,预计需要花费 5 分钟才能阅读完成。

前言

在今天使用 Redis 的时候,在 VMware 虚拟机里面安装的 centos 6.5 系统,在其之上安装了 redis 3.2.9,之后使用 java 进行链接操作的时候就出现了一些连接问题,下面就罗列出遇到的问题以及解决办法。

正文

问题一

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out

出现以上错误,根据提示可以知道是连接超时,是因为 linux 系统没有将 redis 默认端口 6379 进行开放,那么我们只需要打开对应端口即可:

cd /etc
vim sysconfig/iptables

然后在其中插入以下一行内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

然后保存,再将服务重启一下即可:

service iptables restart

问题二

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

根据上方的内容阐述大概就是 Redis 运行在保护模式,只允许在本地回路访问,那么我们只需要将保护模式关闭再重启即可:

# 打开 redis.conf
vim redis.conf
#找到 protected-mode yes,将它改为:protected-mode no
#然后保存,退出 vim
#关闭 redis
./bin/redis-cli shutdown
#开启 redis
./bin/redis-server ./redis.conf

后记

在写项目的时候,遇到的奇葩问题千千万,也许是一个很不起眼的错误就让整个系统崩溃,不过只要静下心了,一切都是过眼云烟~ Redis 在 VMware 虚拟机中本地连接调试错误解决

正文完
使用官方微信小程序体验更多功能
post-qrcode
 8
憧憬Licoy
版权声明:本站原创文章,由 憧憬Licoy 于2017-06-03发表,共计1700字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(33 条评论)
风流王爷 评论达人 LV.1
2017-10-27 15:10:09 回复

第一次来,捧个场,鲜花!!!

 Windows  Chrome  中国上海上海市电信
新澳门银座 评论达人 LV.1
2017-08-11 21:05:14 回复

不错 顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

 Windows  Chrome  中国安徽省池州市电信
新澳门银座 评论达人 LV.1
2017-08-11 21:03:49 回复

玉米苍苍莽莽,如林似海,涛声阵阵,硕大的玉米棒子将春天的梦想,夏天的激情孕育出秋天丰满,携一缕甜丝丝的玉米味儿藏在心中,构思一曲浓浓的乡愁。

 Windows  Chrome  中国安徽省池州市电信
明月学习笔记Blog 评论达人 LV.1
2017-08-02 02:02:37 回复

我最近Redis进程总是无缘无故的被干掉!无语了!

 Windows  Chrome  中国河南省南阳市电信
安心财务 评论达人 LV.1
2017-07-12 15:57:16 回复

很棒~~~·

 Windows  Chrome  中国福建省厦门市联通
ITSS 评论达人 LV.1
2017-07-10 11:50:26 回复

不错,感谢博主分享!!

 Windows  Chrome  中国河南省郑州市联通
bandwagonhost指南 评论达人 LV.1
2017-07-04 10:45:28 回复

朋友 交换链接吗

 Windows  Chrome  中国江苏省苏州市电信
网赚 评论达人 LV.1
2017-07-01 15:52:20 回复

不错的代码!!!!

 Windows  Chrome  中国河南省郑州市联通